/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.mall.shopping.web.xx
   Module Description   :

   Date Created      : 2010/3/25
   Original Author   : feeling
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.mall.shopping.web;

import java.awt.Color;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Random;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author feeling
 * 
 */
public class xx {

	private static JSONObject createJSONObject() {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("username", "huangwuyi");
		jsonObject.put("sex", "男");
		jsonObject.put("QQ", "413425430");
		jsonObject.put("Min.score", new Integer(99));
		jsonObject.put("nickname", "梦中心境");
		jsonObject.put("username", "huangwuyi2");
		jsonObject.put("sex", "男2");
		jsonObject.put("QQ", "413425430");
		jsonObject.put("Min.score", new Integer(99));
		jsonObject.put("nickname", "梦中心境");
		return jsonObject;
	}

	public static Color getRandColor(int fcolor, int bcolor) {
		Random random = new Random();
		if (fcolor > 255) {
			fcolor = 255;
		}
		if (bcolor > 255) {
			bcolor = 255;
		}
		int r = fcolor + random.nextInt(bcolor - fcolor);
		int g = fcolor + random.nextInt(bcolor - fcolor);
		int b = fcolor + random.nextInt(bcolor - fcolor);
		return new Color(r, g, b);
	}

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		JSONArray jsonArray = new JSONArray();
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("ab", "1");
		jsonObject.put("cd", "2");
		jsonArray.add(jsonObject);
		System.out.println(jsonArray);

		System.out.println(jsonArray.getJSONObject(0).get("ab"));
		System.out.println(jsonArray.getJSONObject(0).get("cd"));

		String s = "US6.5";
		System.out.println(s.contains("US6"));
		System.out.println(s.matches("US6"));

		System.out.println(new BigDecimal(361).multiply(new BigDecimal(2.7).multiply(new BigDecimal(0.01))).setScale(1,
				RoundingMode.HALF_UP));
		// Map<String, String> qq = new HashMap<String, String>();
		// qq.put("a", "y");
		// qq.put("b", "y");
		// qq.put("c", "n");
		// qq.put("d", "y");
		// System.out.println(qq.containsValue("p"));
		// // // sample 3
		// Random random = new Random();
		// String msg = "0123456789";
		// List<Font> fontList = new ArrayList<Font>();
		// List<Color> colorList = new ArrayList<Color>();
		// int red = 0, green = 0, blue = 0;
		// for (int i = 0; i < 6; i++) {
		// red = random.nextInt(255);
		// green = random.nextInt(255);
		// blue = random.nextInt(255);
		// colorList.add(new Color(red, green, blue));
		// }
		//
		// fontList.add(new Font("Arial", Font.PLAIN, 32));
		// DefaultWordRenderer dwr = new DefaultWordRenderer(colorList, fontList);
		// WordRenderer wr = dwr;
		//
		// GradiatedBackgroundProducer gbp = new GradiatedBackgroundProducer();
		// gbp.setFromColor(getRandColor(200, 250));
		// gbp.setToColor(getRandColor(160, 200));
		//
		// // 字体空心
		// // ColoredEdgesWordRenderer cwr = new ColoredEdgesWordRenderer(colorList, fontList);
		// for (int i = 0; i < 10; i++) {
		// Builder builder = new Captcha.Builder(110, 40);
		// builder.addText(new DefaultTextProducer(6, msg.toCharArray()), wr);
		// builder.addBackground(gbp);
		// // ---------装饰字体---------------
		// // 字体边框齿轮效果 默认是3
		// int aa = random.nextInt(3);
		// if (aa == 0) {
		// builder.gimp(new BlockGimpyRenderer(2));
		// builder.addNoise(new CurvedLineNoiseProducer(Color.RED, 1.4f));
		// builder.addNoise(new CurvedLineNoiseProducer(Color.BLUE, 1.2f));
		// builder.addNoise(new CurvedLineNoiseProducer(Color.YELLOW, 1f));
		// } else if (aa == 1) {
		// builder.gimp(new FishEyeGimpyRenderer(Color.GRAY, Color.GRAY));
		// } else {
		// builder.gimp();
		// builder.addNoise();
		// }
		// // builder.gimp();
		// // 创建对象
		// Captcha captcha = builder.build();
		// ImageIO.write(captcha.getImage(), "jpeg", new File("r:/feeling2-" + new Date().getTime() + ".png"));
		// }
		// //sample 1
		// byte[] captchaChallengeAsJpeg = null;
		// // the output stream to render the captcha image as jpeg into
		// ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
		// try {
		// // get the session id that will identify the generated captcha.
		// // the same id must be used to validate the response, the session id is a good candidate!
		// // call the ImageCaptchaService getChallenge method
		// BufferedImage challenge = CaptchaServiceSingleton.getInstance().getImageChallengeForID(
		// UUID.randomUUID().toString(), Locale.CHINA);
		//
		// // a jpeg encoder
		// JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
		// jpegEncoder.encode(challenge);
		// } catch (IllegalArgumentException e) {
		// System.out.println(e.fillInStackTrace());
		// } catch (CaptchaServiceException e) {
		// System.out.println(e.fillInStackTrace());
		// return;
		// }
		//
		// captchaChallengeAsJpeg = jpegOutputStream.toByteArray();
		//
		// // flush it in the response
		// FileUtils.writeByteArrayToFile(new File("r:/feeling-" + new Date().getTime() + ".png"), captchaChallengeAsJpeg);

		// sample 2
		// for (int i = 0; i < 1; i++) {
		// ValidateCode vCode = new ValidateCode(180, 80, 6, 120);
		// try {
		// String path = "r:/" + new Date().getTime() + ".png";
		// System.out.println(vCode.getCode() + " >" + path);
		// vCode.write(path);
		// File f = new File(path);
		// InputStream inputStream = new FileInputStream(f);
		// BufferedImage src = null;
		// BufferedImage dst = null;
		// src = ImageIO.read(inputStream);
		// Image image = null;
		// Graphics g = src.getGraphics();
		// GradientWipeFilter filter = new GradientWipeFilter();
		// filter.setDensity(3f);
		// filter.setInvert(true);
		// // dst = filter.createCompatibleDestImage(src, ColorModel.getRGBdefault());
		// BufferedImage aaa = filter.filter(src, dst);
		// ImageIO.write(aaa, "jpeg", new File("r:/abc4.png"));

		// Create the filter
		// ImageProducer imageProducer = (ImageProducer) src.getGraphics();
		//
		// FilteredImageSource filteredSrc = new FilteredImageSource(imageProducer, new ImageFilter());
		//
		// // Create the filtered image
		// image = Toolkit.getDefaultToolkit().createImage(filteredSrc);

		// HalftoneFilter filter = new HalftoneFilter();
		// filter.createCompatibleDestImage(src, ColorModel.getRGBdefault());

		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		// }

		// System.out.println(StringUtils.isNotBlank(null));
		// System.out.println((int) (Math.random() * 1000));

		// System.out.println(UUID.randomUUID());
		// System.out.println(UUID.randomUUID().clockSequence());
		// List list = new ArrayList();
		// list.add(true);
		//
		// System.out.println(list);
		// JSONArray jsonArray1 = new JSONArray();
		//
		// // JSONObject jso11 = new JSONObject();
		// Map<String, String> m11 = new HashMap<String, String>();
		// m11.put("SPEC_ID", "123");
		// m11.put("SPEC_NAME", "M");
		// Map<String, String> m12 = new HashMap<String, String>();
		// m12.put("SPEC_ID", "456");
		// m12.put("SPEC_NAME", "S");
		// jsonArray1.add(0, m11);
		// jsonArray1.add(1, m12);
		//
		// Map<String, String> m21 = new HashMap<String, String>();
		// m21.put("SPEC_ID", "222");
		// m21.put("SPEC_NAME", "XL");
		// JSONArray jsonArray2 = new JSONArray();
		// m21.put("SPEC_ID", "789");
		// m21.put("SPEC_NAME", "XL");
		// jsonArray2.add(0, m21);
		// JSONObject jso = new JSONObject();
		// jso.put("紅色", jsonArray1);
		// jso.put("藍色", jsonArray2);
		//
		// Iterator<String> keyIter = jso.keys();
		// while (keyIter.hasNext()) {
		// String objName = keyIter.next();
		// JSONArray array = JSONArray.fromObject(jso.getString(objName));
		// for (int i = 0; i < array.size(); i++) {
		// JSONObject jsonObject = array.getJSONObject(i);
		// System.out.println(jsonObject.get("SPEC_ID") + ":" + jsonObject.get("SPEC_NAME"));
		// }
		// }

		// JSONObject jsonObject = JSONObject.fromObject(jsonArray3);
		/*
		 * JSONObject jsonObject = createJSONObject(); // 输出jsonobject对象 System.out.println("jsonObject==>" + jsonObject);
		 * 
		 * // 判读输出对象的类型 boolean isArray = jsonObject.isArray(); boolean isEmpty = jsonObject.isEmpty(); boolean isNullObject
		 * = jsonObject.isNullObject(); System.out.println("isArray:" + isArray + " isEmpty:" + isEmpty + " isNullObject:" +
		 * isNullObject);
		 * 
		 * // 添加属性 jsonObject.element("address", "福建省厦门市"); System.out.println("添加属性后的对象==>" + jsonObject);
		 * 
		 * // 返回一个JSONArray对象 JSONArray jsonArray = new JSONArray(); jsonArray.add(0, "this is a jsonArray value");
		 * jsonArray.add(1, "another jsonArray value"); jsonObject.element("jsonArray", jsonArray); JSONArray array =
		 * jsonObject.getJSONArray("jsonArray"); System.out.println("返回一个JSONArray对象：" + array); // 添加JSONArray后的值 //
		 * {"username"
		 * :"huangwuyi","sex":" 男","QQ":"413425430","Min.score":99,"nickname":"梦中心境","address":"福建省厦门市","jsonArray"
		 * :["this is a jsonArray value","another jsonArray value"]} System.out.println("结果=" + jsonObject);
		 * 
		 * // 根据key返回一个字符串 String username = jsonObject.getString("username"); System.out.println("username==>" + username);
		 * 
		 * // 把字符转换为 JSONObject String temp = jsonObject.toString(); JSONObject object = JSONObject.fromObject(temp); //
		 * 转换后根据Key返回值 System.out.println("qq=" + object.get("QQ")); // System.out.println(new BigDecimal(17).divide(new
		 * BigDecimal(2), BigDecimal.ROUND_UP)); // String ca = "406 "; // String ca1 = " "; // String ca2 = " 406 "; //
		 * String ca3 = null; // System.out.println("ca:" + StringUtils.replace(ca, " ", "")); // System.out.println("ca1:"
		 * + StringUtils.replace(ca1, " ", "")); // System.out.println("ca2:" + StringUtils.replace(ca2, " ", "")); //
		 * System.out.println("ca3:" + StringUtils.replace(ca3, " ", "")); // List<List<String>> gSegment = new
		 * LinkedList<List<String>>(); // LinkedList<String> aa = new LinkedList<String>(); // aa.add("a"); // aa.add("b");
		 * // aa.add("c"); // gSegment.add(aa); // LinkedList<String> bb = new LinkedList<String>(); // bb.add("d"); //
		 * bb.add("e"); // gSegment.add(bb); // LinkedList<String> cc = new LinkedList<String>(); // cc.add("f"); //
		 * cc.add("g"); // cc.add("h"); // gSegment.add(cc); // System.out.println(gSegment); // // List<String> result =
		 * new LinkedList<String>(); // runArray(0, gSegment, result);
		 */
	}
	// public static void runArray(int i, List<List<String>> gSegment, List<String> result) {
	// for (int j = 0; j < gSegment.get(i).size(); j++) {
	// System.out.println("i:" + i);
	// result.add(gSegment.get(i).get(j));
	//
	// if ((i + 1) < gSegment.size()) {
	// // 遞迴
	// runArray(i + 1, gSegment, result);
	// } else {
	// // 列印結果
	// for (String elm : result) {
	// System.out.print(elm + ", ");
	// }
	// System.out.println();
	// }
	// }
	// }

	// BigDecimal aa = new BigDecimal(60);
	// BigDecimal bb = new BigDecimal(60.0);
	// System.out.println(aa.compareTo(bb));
	// System.out.println(new BigDecimal(1230.56).setScale(1, RoundingMode.UP));
	// String addonResult = "yny";
	// System.out.println(StringUtils.countMatches(addonResult, "n"));
	// System.out.println(StringUtils.length(addonResult));
	// String xxx =
	// "{'editShipFare':'0.0','phone':'222222','addCmpPd':'','addr':'11111111111111','finalTotalAmount':'479.0','city':'???','editCoupon':'0.0','paytype':'10','zipCode':'111','province':'??','editBonus':'0.0','couponInfo':'','district':'????,N,????,?','mail':'wch1213@gmail.com','totalDiscount':'0','subVrtlBlnc':'','areaCode':'222','buyNowCartId':'39c29249-13a6-4075-9599-975923c3c46d','finalMustPay':'479.0','editTotalAmount':'479.0','campaigns':'ff8081812c0ba49b012c0c08435c0001','addCmpPdId':'','isBuyNow':'Y_','canUse':'0','extension':'','editAmount_':'479','0','contactName':'test2','mobile':'222222222'}";
	// JSONArray.fromObject(xxx);
	// JSONArray jsonArray = JSONArray.fromObject("['json','is','easy']");
	// JSONArray jsonArray = JSONArray.fromObject(xxx);
	// System.out.println(jsonArray);
	// String json =
	// "{\"editShipFare\":\"0.0\",\"phone\":\"222222\",\"addCmpPd\":\"\",\"addr\":\"11111111111111\",\"finalTotalAmount\":\"479.0\",\"city\":\"???\",\"editCoupon\":\"0.0\",\"paytype\":\"10\",\"zipCode\":\"111\",\"province\":\"??\",\"editBonus\":\"0.0\",\"couponInfo\":\"\",\"district\":\"????,N,????,?\",\"mail\":\"wch1213@gmail.com\",\"totalDiscount\":\"0\",\"subVrtlBlnc\":\"\",\"areaCode\":\"222\",\"buyNowCartId\":\"39c29249-13a6-4075-9599-975923c3c46d\",\"finalMustPay\":\"479.0\",\"editTotalAmount\":\"479.0\",\"campaigns\":\"ff8081812c0ba49b012c0c08435c0001\",\"addCmpPdId\":\"0\",\"isBuyNow\":\"Y_\",\"canUse\":\"0\",\"extension\":\"\",\"editAmount_\":\"479\",\"0\",\"contactName\":\"test2\",\"mobile\":\"222222222\"}";
	// JSONObject jsonObject = JSONObject.fromObject(json);
	// Object bean = JSONObject.toBean(jsonObject);
	// System.out.println(bean);
	// JSONObject jsonObject = JSONObject.fromObject(xxx);
	// Object bean = JSONObject.toBean(jsonObject);

	// System.out.println(DateUtil.getLastTimestamp(0, DateUtil.getCurrentTime()).getTime());
	// List<String> abc = new ArrayList<String>();
	// abc.add("1");
	// abc.add("3");
	// abc.add("2");
	// System.out.println(NumberUtils.createInteger(ArrayUtils.toString(abc).replace("[", "").replace("]", "")));
	// Date aa = new Date();
	// System.out.println(aa.getHours());
	// System.out.println(NumberUtils.isDigits("232DADCDE"));
	// System.out.println(NumberUtils.isNumber("232DADCDE"));
	// System.out.println(NumberUtils.isDigits("232.42342"));
	// System.out.println(NumberUtils.isNumber("232.42342"));
	// String greeting = "Hello world";
	//
	// for (int i = 0; i < greeting.length(); i++) {
	// // System.out.flush();
	// System.out.write(greeting.charAt(i));
	// // System.out.write();
	// }

	// System.out.println(StringUtils.indexOfAny("80", new String[] { "30", "40" }));
	// Map<String, String> m = new HashMap<String, String>();
	//
	// m.put("Mickey", "Mouse");
	//
	// m.put("Mickey", "Mantle");
	//
	// System.out.println(m.size());
	//
	// Map<String, String> n = new HashMap<String, String>();
	// n.put(new String("Mickey"), "Mouse");
	//
	// n.put(new String("Mickey"), "Mantle");
	//
	// System.out.println(n.size());

	// File seofile = new File(ServerValue.getFrontApachePath() + "/static/server/frontpage.properties");
	// FileUtils.forceDeleteOnExit(seofile);
	// seofile = new File(ServerValue.getFrontApachePath() + "/static/server/frontpage.properties");
	//
	// File file = new File(ServerValue.getFrontApachePath() + "/static/server/seo_basic.txt");
	// String content = FileUtils.readFileToString(file, "UTF-8");
	// Reader reader = new StringReader(content);
	// Properties props = new Properties();
	// props.load(reader);
	// reader.close();
	// Set ss = props.keySet();
	// Iterator iter = ss.iterator();
	// while (iter.hasNext()) {
	// Object obj = iter.next();
	// System.out.println("obj:::" + obj);
	// props.put(obj, props.get(obj));
	// }
	// FileOutputStream writer = new FileOutputStream(seofile);
	// props.store(writer, "");

	// Calendar calendarForOnlinePay = Calendar.getInstance();
	// calendarForOnlinePay.add(Calendar.DAY_OF_MONTH, -3);
	// System.out.println(calendarForOnlinePay.getTime());
	// 860DC7530D4293A5801726671D7FA5B3
	// System.out.println("decode:" + PasswordUtils.decodePassword("0A33732A1993FDF7AFE0F0D738BC4EF2", null));
	// String aa = "abc";
	// System.out.println(StringUtils.substring(aa, 6, 10));
	// System.out.println("xxx:" + URLEncoder.encode(URLEncoder.encode("耀点", "UTF-8"), "UTF-8"));
	// System.out.println("xxx2:" + URLDecoder.decode("%C3%84%C2%A3%3F%C2%A4%C2%A4%C2%A4%C3%A5", "UTF-8"));

	// String[] aaa = new String[] { "0", "1", "4", "5", "6N" };
	// System.out.println(StringUtils.containsAny("01456N", "6N,6,6,6"));
	// BigDecimal totalWeight = new BigDecimal(108);
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000), 3, 0));
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000), 3, 1));
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000), 3, 2));
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000), 3, 3));
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000), 3, 4));
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000), 3, 5));
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000), 3, 6));
	// System.out.println("XXXXXXXXXXXX = " + totalWeight.divide(new BigDecimal(1000)));
	// BigDecimal totalWeight1 = new BigDecimal(781.23);
	// System.out.println("XXXXXXXXXXXX = " + totalWeight1.divide(new BigDecimal(1000)).setScale(3));
	// System.out.println("XXX:=" + new BigDecimal(0).compareTo(new BigDecimal(0.00)));
	// Calendar calendar = Calendar.getInstance();
	// Date today = new Date();
	// today.setHours(0);
	// today.setMinutes(0);
	// today.setSeconds(0);
	// System.out.println("today:" + today);
	// calendar.setTime(today);
	// System.out.println("xxxx " + calendar.getTimeInMillis());

}
